MODE=debug
GNATMAKE=@GNATMAKE@
GNATCLEAN=@GNATCLEAN@
GPRPATH=@GPRPATH@
SVN=svn

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
datarootdir= @datarootdir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@

top_builddir = .
config_dir=${datadir}/dynamo

CPUS := @NR_CPUS@
MAKE_ARGS=-XMODE=${MODE} -XPROCESSORS=$(CPUS)

MAT_GTKADA=@MAT_GTKADA@
MKDIR=mkdir
CP=cp

# Build executables for all mains defined by the project.
all build:
	$(GNATMAKE) -p -P "$(GPRPATH)" $(MAKE_ARGS)

# Not intended for manual invocation.
# Invoked if automatic builds are enabled.
# Analyzes only on those sources that have changed.
# Does not build executables.
autobuild:
	$(GNATMAKE) -gnatc -c -k  -P "$(GPRPATH)" $(MAKE_ARGS)

# Clean the root project of all build products.
clean:
	-$(GNATCLEAN) -q -P "$(GPRPATH)"

# Check *all* sources for errors, even those not changed.
# Does not build executables.
analyze:
	$(GNATMAKE) -f  -gnatc -c -k  -P "$(GPRPATH)" $(MAKE_ARGS)

# Clean, then build executables for all mains defined by the project.
rebuild: clean build

bin/mat_harness:  bin/matp
	$(GNATMAKE) -p -Ptests $(MAKE_ARGS)

bin/matp:		Makefile $(GPRPATH)
	$(GNATMAKE) -P "$(GPRPATH)" $(MAKE_ARGS)

test:			bin/mat_harness
	bin/mat_harness

install:
	$(INSTALL_PROGRAM) bin/matp $(bindir)/
	$(INSTALL) man/mat.1 $(mandir)/man1/mat.1


# Development targets that requires ayacc and aflex to be installed.
# Do not call these unless you modify the lex/yacc grammar.
parser:	
	cd src/parser; \
	ayacc mat-expressions-parser.y off off off off off .x ; \
    sed -e '/with YY_Sizes;/d' \
	    -e 's,yy_sizes.stack_size,8192,' \
		mat-expressions-parser.x > mat-expressions-parser.a
	cd src/parser; \
	gnatchop -w mat-expressions-parser.a
	cd src/parser; \
	  rm mat-expressions-parser.a mat-expressions-parser.x

lexer:	
	cd src/parser; \
	aflex mat-expressions-lexer.l
	cd src/parser; \
    sed -e 's,mat.expressions.lexer_io,MAT.Expressions.Parser_IO,g' \
	    < mat-expressions-lexer.a > mat-expressions-lexer.b ; \
	mv mat-expressions-lexer.b mat-expressions-lexer.a
	cd src/parser; \
	gnatchop -w mat-expressions-lexer.a ; \
	gnatchop -w mat-expressions-lexer_dfa.a
	cd src/parser; \
    sed -e 's,mat.expressions.lexer_io,MAT.Expressions.Parser_IO,g' \
	    < mat-expressions-lexer_io.a > mat-expressions-parser_io.a
	cd src/parser; \
	  rm mat-expressions-parser_io.a mat-expressions-lexer_io.a \
	     mat-expressions-lexer.a mat-expressions-lexer_dfa.a
